<template>
  <el-dialog
      :title="!dataForm.emrHzId ? '新增' : '修改'"
      :close-on-click-modal="false"
      :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="80px">
<el-form-item label="联系电话" prop="emrHzPhone">
  <el-input v-model="dataForm.emrHzPhone" placeholder="联系电话"></el-input>

</el-form-item>
<el-form-item label="登录密码" prop="emrHzPwd">
  <el-input v-model="dataForm.emrHzPwd" placeholder="登录密码"></el-input>

</el-form-item>
<el-form-item label="患者姓名" prop="emrHzName">
  <el-input v-model="dataForm.emrHzName" placeholder="患者姓名"></el-input>

</el-form-item>
<el-form-item label="患者性别" prop="emrHzSex">
  <el-select placeholder="患者性别" v-model="dataForm.emrHzSex">
    <el-option label="男" :value="1"></el-option>
    <el-option label="女" :value="0"></el-option>
  </el-select>
</el-form-item>
<el-form-item label="患者年龄" prop="emrHzAge">
  <el-input v-model="dataForm.emrHzAge" placeholder="患者年龄"></el-input>

</el-form-item>
<el-form-item label="患者职业" prop="emrHzJob">
  <el-input v-model="dataForm.emrHzJob" placeholder="患者职业"></el-input>

</el-form-item>
<el-form-item label="出生日期" prop="emrHzBirth">
  <el-input v-model="dataForm.emrHzBirth" placeholder="出生日期"></el-input>

</el-form-item>
<el-form-item label="出生地" prop="emrHzPlace">
  <el-input v-model="dataForm.emrHzPlace" placeholder="出生地"></el-input>

</el-form-item>
<el-form-item label="卡号" prop="emrHzCard">
  <el-input v-model="dataForm.emrHzCard" placeholder="卡号"></el-input>

</el-form-item>
<el-form-item label="婚姻状态" prop="emrHzMarry">
  <el-input v-model="dataForm.emrHzMarry" placeholder="婚姻状态"></el-input>

</el-form-item>
<el-form-item label="过敏药物" prop="emrHzGm">
  <el-input v-model="dataForm.emrHzGm" placeholder="过敏药物"></el-input>

</el-form-item>
<el-form-item label="患者头像" prop="emrHzImg">
  <el-input v-model="dataForm.emrHzImg" placeholder="患者头像"></el-input>

</el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          emrHzId: 0,
          emrHzPhone: '',
          emrHzPwd: '',
          emrHzName: '',
          emrHzSex: '',
          emrHzAge: '',
          emrHzJob: '',
          emrHzBirth: '',
          emrHzPlace: '',
          emrHzCard: '',
          emrHzMarry: '',
          emrHzGm: '',
          emrHzImg: ''
        },
        dataRule: {
          emrHzPhone: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          emrHzPwd: [
            { required: true, message: '登录密码不能为空', trigger: 'blur' }
          ],
          emrHzName: [
            { required: true, message: '患者姓名不能为空', trigger: 'blur' }
          ],
          emrHzSex: [
            { required: true, message: '患者性别不能为空', trigger: 'blur' }
          ],
          emrHzAge: [
            { required: true, message: '患者年龄不能为空', trigger: 'blur' }
          ],
          emrHzJob: [
            { required: true, message: '患者职业不能为空', trigger: 'blur' }
          ],
          emrHzBirth: [
            { required: true, message: '出生日期不能为空', trigger: 'blur' }
          ],
          emrHzPlace: [
            { required: true, message: '出生地不能为空', trigger: 'blur' }
          ],
          emrHzCard: [
            { required: true, message: '卡号不能为空', trigger: 'blur' }
          ],
          emrHzMarry: [
            { required: true, message: '婚姻状态不能为空', trigger: 'blur' }
          ],
          emrHzGm: [
            { required: true, message: '过敏药物不能为空', trigger: 'blur' }
          ],
          emrHzImg: [
            { required: true, message: '患者头像不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.emrHzId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.emrHzId) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/emrhzinfo/info/${this.dataForm.emrHzId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.emrHzPhone = data.emrHzInfo.emrHzPhone
                this.dataForm.emrHzPwd = data.emrHzInfo.emrHzPwd
                this.dataForm.emrHzName = data.emrHzInfo.emrHzName
                this.dataForm.emrHzSex = data.emrHzInfo.emrHzSex
                this.dataForm.emrHzAge = data.emrHzInfo.emrHzAge
                this.dataForm.emrHzJob = data.emrHzInfo.emrHzJob
                this.dataForm.emrHzBirth = data.emrHzInfo.emrHzBirth
                this.dataForm.emrHzPlace = data.emrHzInfo.emrHzPlace
                this.dataForm.emrHzCard = data.emrHzInfo.emrHzCard
                this.dataForm.emrHzMarry = data.emrHzInfo.emrHzMarry
                this.dataForm.emrHzGm = data.emrHzInfo.emrHzGm
                this.dataForm.emrHzImg = data.emrHzInfo.emrHzImg
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/emrhzinfo/${!this.dataForm.emrHzId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'emrHzId': this.dataForm.emrHzId || undefined,
                'emrHzPhone': this.dataForm.emrHzPhone,
                'emrHzPwd': this.dataForm.emrHzPwd,
                'emrHzName': this.dataForm.emrHzName,
                'emrHzSex': this.dataForm.emrHzSex,
                'emrHzAge': this.dataForm.emrHzAge,
                'emrHzJob': this.dataForm.emrHzJob,
                'emrHzBirth': this.dataForm.emrHzBirth,
                'emrHzPlace': this.dataForm.emrHzPlace,
                'emrHzCard': this.dataForm.emrHzCard,
                'emrHzMarry': this.dataForm.emrHzMarry,
                'emrHzGm': this.dataForm.emrHzGm,
                'emrHzImg': this.dataForm.emrHzImg
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
